<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet"
type="text/css" />
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet"
type="text/css" />
<link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.css"
rel="stylesheet" type="text/css" />
<link href="lib/region/css/city-picker.css" rel="stylesheet"
type="text/css" />
<link href="lib/region/css/main.css?v=" + Math.random() rel="stylesheet"
type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>发布广告</title>
</head>
<body>
	<div class="pd-20">
		<form action="<%=path%>/backstage/advert-add" method="post"
			class="form form-horizontal" id="form-u_advert-add">
			<input type="hidden" id="id" name="id" value='${u_advert.id}' />

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">企业主：</label>
				<div class="formControls col-xs-8 col-sm-5">
					<span class="select-box"><select name="ent_id"
						class="select" datatype="*" nullmsg="请选择类型">
						<c:forEach items="${entrepreneurs}" var="entrepreneur">
						<option value="${entrepreneur.id}_${entrepreneur.user_id}"
						<c:if test="${u_advert.ent_id==entrepreneur.id}"> selected="selected"</c:if>>${entrepreneur.corp_fname}</option>
					</c:forEach>
				</select></span>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">广告位：</label>
			<div class="formControls col-xs-8 col-sm-5">
				<!--:0红包广告，1位置广告-->
				<span class="select-box"> <select name="position_id"
					id="position_id" onchange="showPrice()" class="select"
					datatype="n" size="1" nullmsg="请选择广告位">
					<c:forEach items="${u_advert_positions}" var="position">
					<c:if test="${position.id !=3 and position.id!=8}">
					<option value="${position.id}"
					data_price="${position.unit_price}"
					<c:if test="${u_advert.position_id==position.id}"> selected="selected"</c:if>>${position.position_name}</option>
				</c:if>
			</c:forEach>
		</select>
	</span>
</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">单价（元/天）：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<div class="col-sm-10" id="positionprice"></div>
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">投放开始时间：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<input type="text" class="input-text Wdate" readonly="readonly"
		onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d',maxDate:'#F{$dp.$D(\'end_time\')}',onpicked:function(){selectdate();}})"
		value="${u_advert.start_time}" placeholder="" id="start_time"
		name="start_time" datatype="*" nullmsg="不能为空">
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">投放结束时间：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<input type="text" class="input-text Wdate" readonly="readonly"
		value="${u_advert.end_time}"
		onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'start_time\')}',onpicked:function(){selectdate();}})"
		placeholder="" id="end_time" name="end_time" datatype="*"
		nullmsg="不能为空">
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">投放时间天数：</label>
	<div class="formControls col-xs-8 col-sm-5" id="daynum"></div>
</div>


<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">总计（元）</label>
	<div class="formControls col-xs-8 col-sm-5">
		<input type="text" class="form-control" value="" id="total_amount"
		readonly="readonly" name="total_amount">
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">类型：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<!--:0红包广告，1位置广告-->
		<span class="select-box"> <select name="resource_type"
			class="select" datatype="n" nullmsg="请选择广告类型">
			<option value="0"
			<c:if test="${u_advert.resource_type==0}"> selected="selected"</c:if>>图片</option>
			<option value="1"
			<c:if test="${u_advert.resource_type==1}"> selected="selected"</c:if>>视频</option>
		</select>
	</span>
</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">投放地区：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<input id="city-picker3" class="form-control" readonly
		name="regioninfo" type="text"
		value="<c:if test="${u_advert.province!=''}">${u_advert.province}</c:if><c:if test="${u_advert.city!=''}">/${u_advert.city}</c:if><c:if test="${u_advert.area!=''}">/${u_advert.area}</c:if>"
		data-toggle="city-picker">
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">投放范围：</label>
	<!--  -1不限，0全城，其它数字为距离值km -->
	<div class="formControls col-xs-8 col-sm-5">
		<input type="text" class="input-text"
		value="${u_advert.distance_range}" placeholder="" id=""
		name="distance_range" datatype="*" nullmsg="不能为空">
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">年龄段:</label>
	<div class="formControls col-xs-8 col-sm-5">
		<!--:0红包广告，1位置广告-->
		<span class="select-box"> <select name="age_range"
			class="select" datatype="*" nullmsg="请选择年龄段">
			<c:forEach items="${ageranges}" var="agerange">
			<option value="${agerange.id}"
			<c:if test="${u_advert.age_range == agerange.id}"> selected="selected"</c:if>>${agerange.display_name}</option>
		</c:forEach>
	</select>
</span>
</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">职业：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<span class="select-box"> <select name="job_title"
			class="select" datatype="*" nullmsg="请选择职业">
			<c:forEach items="${professions}" var="profession">
			<option value="${profession.item_value}"
			<c:if test="${u_advert.job_title==profession.item_value}"> selected="selected"</c:if>>${profession.display_name}</option>
		</c:forEach>
	</select></span>
</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">兴趣关键字：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<div style="line-height: 28px;">
			<c:forEach items="${alllabels}" var="label">
			${label.label_name}:
			<c:forEach items="${label.childLabel}" var="clabel">
			<input type="checkbox" name="label" style="width: 10px;" <c:if test="${fn:contains(u_advert.interest_key,clabel.label_name)}">checked="checked"</c:if>
			value="${clabel.label_name}">&nbsp;${clabel.label_name}&nbsp;&nbsp;
		</c:forEach>
		<br />
	</c:forEach>
</div>
</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">标题：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<input type="text" class="input-text" value="${u_advert.adv_name}"
		placeholder="" id="" name="adv_name" datatype="*" nullmsg="不能为空">
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">描述：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<textarea class="textarea" placeholder="" rows="" cols=""
		name="adv_desc" datatype="*" nullmsg="不能为空">${u_advert.adv_desc}</textarea>
	</div>
</div>


<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">详情页URL：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<input type="text" class="input-text"
		value="${u_advert.detail_url}" placeholder="" id=""
		name="detail_url" datatype="*" nullmsg="不能为空">
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">详细地址：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<input type="text" class="input-text" value="${u_advert.address}"
		placeholder="" id="" name="address" datatype="*" nullmsg="不能为空">
	</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">广告图片（视频）：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<div id="fileList_covers" class="uploader-list">
			<c:if test="${!empty u_advert.covers}">
			<div class="file-item thumbnail upload-state-done">
				<img style="width:190px;height:190px;" src="${u_advert.covers}" />
				<div class="info"></div>
			</div>
		</c:if>
	</div>
	<div id="filePicker_covers">选择</div>
	<input type="hidden" class="input-text" value="${u_advert.covers}"
	placeholder="" id="covers" name="covers" datatype="*"
	nullmsg="不能为空">
</div>
</div>

<div class="row cl">
	<label class="form-label col-xs-4 col-sm-3">排序：</label>
	<div class="formControls col-xs-8 col-sm-5">
		<input type="text" class="input-text" value="${u_advert.sort}"
		placeholder="" id="" name="sort" datatype="n" nullmsg="不能为空">
	</div>
</div>

<div class="row cl">
	<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
		<button onClick="u_advert_save_submit();"
		class="btn btn-primary radius" type="submit">
		<i class="Hui-iconfont">&#xe632;</i> 保存并提交
	</button>
	<button onClick="layer_close();" class="btn btn-default radius"
	type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
</div>
</div>
</form>
</div>
</div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
<script type="text/javascript"
src="lib/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript"
src="lib/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript"
src="lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript"
src="lib/ueditor/1.4.3/ueditor.all.min.js"></script>
<script type="text/javascript" src="lib/region/js/city-picker.data.js"></script>
<script type="text/javascript" src="lib/region/js/city-picker.js"></script>
<script type="text/javascript" src="lib/region/js/main.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="js/uthinkjs/advert.js"></script>
<script type="text/javascript">
	function u_advert_save_submit() {
		$("#form-u_advert-add").Validform({
			tiptype : 2,
			ajaxPost : true,
			callback : function(form) {
				var index = parent.layer.getFrameIndex(window.name);
					if (index) {//关闭弹出层
						parent.$('.btn-refresh').click();
						parent.layer.close(index);
					} else {//单独的页面
						location.href = "<%=path%>/backstage/advert-list";
					}
				}
			});
	}

		// 图片上传demo
		$(function() {
			var $covers = $('#fileList_covers'),
			// 优化retina, 在retina下这个值是2
			ratio = window.devicePixelRatio || 1,
			// 缩略图大小
			thumbnailWidth = 100 * ratio, thumbnailHeight = 100 * ratio,uploader_covers;
			// 初始化广告封面上传空间
			uploader_covers = WebUploader.create({
				// 自动上传。
				auto : true,
				// swf文件路径
				swf : 'lib/webuploader/0.1.5/Uploader.swf',
				// 文件接收服务端。
				server : '<%=path%>/backstage/common/uploadPic',
				// 选择文件的按钮。可选。
				// 内部根据当前运行是创建，可能是input元素，也可能是flash.
				pick : '#filePicker_covers',
				// 只允许选择文件，可选。
				accept : {
					title : 'Images',
					extensions : 'gif,jpg,jpeg,bmp,png,mp4,MP4',
					mimeTypes : 'image/jpg,image/jpeg,image/png,'
				},
				formData : {
					foldername : 'advert'
				}
			});
			// 文件上传成功，给item添加成功class, 用样式标记上传成功。
			uploader_covers.on('uploadSuccess', function(file, response) {
				$('#' + file.id).addClass('upload-state-done');
				if (response.error == "0000") {
					$("#covers").val(response.datas);
				}
			});

			uploader_covers.on(
				'fileQueued',
				function(file) {
					var $li = $('<div id="' + file.id + '" class="file-item thumbnail">'
						+ '<img>'
						+ '<div class="info">'
						+ file.name + '</div>' + '</div>'), $img = $li
					.find('img');
					$covers.html($li);
					uploader_covers.makeThumb(file, function(error,
						src) {
						if (error) {
							$img.replaceWith('<span>不能预览</span>');
							return;
						}
						$img.attr('src', src);
					}, thumbnailWidth, thumbnailHeight);
				});

			// 文件上传失败，现实上传出错。
			uploader_covers.on('uploadError', function(file) {
				var $li = $('#' + file.id), $error = $li.find('div.error');

				// 避免重复创建
				if (!$error.length) {
					$error = $('<div class="error"></div>').appendTo($li);
				}

				$error.text('上传失败');
			});

			// 完成上传完了，成功或者失败，先删除进度条。
			uploader_covers.on('uploadComplete', function(file) {
				$('#' + file.id).find('.progress').remove();
			});
		});
	</script>
</body>
</html>

